package com.platform.modules.cpt.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.platform.common.utils.RestResponse;
import com.platform.modules.cpt.entity.CptAcceptanceSuperviseTeamEntity;
import com.platform.modules.cpt.service.CptAcceptanceService;
import com.platform.modules.cpt.service.CptAcceptanceSuperviseTeamService;
import com.platform.modules.quality.vo.CommonResult;
import com.platform.modules.sys.controller.AbstractController;
import com.platform.modules.sys.entity.SysUserEntity;
import com.platform.util.DocUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * Controller
 *
 * @author biaohuaming
 * @date 2020-02-24 15:28:20
 */
@Api(tags = "竣工验收 工程质量监督人员")
@RestController
@RequestMapping("cpt/acceptance/superviseTeam")
public class CptAcceptanceSuperviseTeamController extends AbstractController {

    @Autowired
    private CptAcceptanceService cptAcceptanceService;

    @Autowired
    private CptAcceptanceSuperviseTeamService cptAcceptanceSuperviseTeamService;

    @Autowired
    private DocUtil docUtil;


    /**
     * @descr 查询<br>
     * @param id
     * @return
     */
    @ApiOperation(value = "查询工程质量监督人员数据")
    @PostMapping("/view")
    public RestResponse view(@RequestParam String id) {
    	Map<String, Object> params = getParams();
    	params.put("ID", id);
    	CptAcceptanceSuperviseTeamEntity entity = cptAcceptanceSuperviseTeamService.queryOne(params);
        return RestResponse.success().put("data", entity);
    } 
    
    /**
     * @param prjId
     * @return
     */
    @ApiOperation(value = "查询工程质量监督人员数据列表")
    @GetMapping("/list")
    public RestResponse list(@RequestParam(required = false) String prjId, @RequestParam String cptId) {
    	Map<String, Object> params = getParams();
        params.put("cptId", cptId);
    	List<CptAcceptanceSuperviseTeamEntity> list = cptAcceptanceSuperviseTeamService.queryList(params);
    	return RestResponse.success().put("list", list);
    } 
    
    /**
     * @param cptAcceptanceSuperviseTeamEntity
     * @return
     */
    @ApiOperation(value = "保存工程质量监督人员数据")
    @PostMapping("save")
    public CommonResult save(CptAcceptanceSuperviseTeamEntity cptAcceptanceSuperviseTeamEntity) {
    	SysUserEntity sysUserEntity = this.getUser();
    	if(StringUtils.isBlank(cptAcceptanceSuperviseTeamEntity.getId())) {
    		cptAcceptanceSuperviseTeamEntity.setCreateTime(new Date());
    		cptAcceptanceSuperviseTeamEntity.setCreateUser(sysUserEntity.getUserId());
    	}else {
    		cptAcceptanceSuperviseTeamEntity.setUpdateTime(new Date());
    		cptAcceptanceSuperviseTeamEntity.setUpdateUser(sysUserEntity.getUserId());
    	}
        cptAcceptanceSuperviseTeamService.save(cptAcceptanceSuperviseTeamEntity);
        return CommonResult.success();
    }

    @ApiOperation(value = "删除工程质量监督人员记录", notes = "删除工程质量监督人员记录")
    @DeleteMapping("/remove/{id}")
    public RestResponse removeById(@PathVariable(value="id") String id) {
    	cptAcceptanceSuperviseTeamService.removeById(id);
        return RestResponse.success();
    }
}
